又是劳累的一天
来源:互联网 发布:淘宝运营表格 编辑:程序博客网 时间:2024/05/01 13:37
今天者的特累,连续看了4天的C#语法,今天终于动手写项目了!~哦!长出一口恶气啊!累啊!~最近在戒烟,想抽,可是兜里还有几个钢板,都不够吃中午饭了~~今天是周五,明天还要上班啊!~郁闷 啊!~没办法,我就是着命运啊!~按照书上做了c#的游戏,可惜调试总是出错!~懵!~ 不说废话了~!~把代码贴出来看看!~
//三角形的类代码
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
class Triangle:Sharp
{
protected int a;
protected int b;
protected int c;
public Triangle(int va, int vb, int vc) {
a = va;
b = vb;
c = vc;
}
public override int GetArea()
{
int s = (a + b + c) / 2;
int area = (int)Math.Sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}
public override void Draw()
{
Console.WriteLine("Triangle");
Console.WriteLine("*");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * *");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
class Triangle:Sharp
{
protected int a;
protected int b;
protected int c;
public Triangle(int va, int vb, int vc) {
a = va;
b = vb;
c = vc;
}
public override int GetArea()
{
int s = (a + b + c) / 2;
int area = (int)Math.Sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}
public override void Draw()
{
Console.WriteLine("Triangle");
Console.WriteLine("*");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * *");
}
}
}
//所有图形的基类
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
public class Sharp
{
public virtual void Draw(){;}
public virtual int GetArea() {
return 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
public class Sharp
{
public virtual void Draw(){;}
public virtual int GetArea() {
return 0;
}
}
}
//矩形的类代码
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
public class Rectangle:Sharp
{
protected int a;
protected int b;
public Rectangle ( int va,int vb){
a = va;
b = vb;
}
public override int GetArea(){
int area=a*b;
return area;
}
public override void Draw(){
Console.WriteLine("Rectangle");
Console.WriteLine("* * * *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * * *");
}
}
public class Square : Rectangle {
public Square(int va) : base(va,va) {;}
public override void Draw()
{
Console.WriteLine("Square");
Console.WriteLine("****");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("****");
}
}
public class RectEqualTriangle : Rectangle {
new protected int a;
public RectEqualTriangle(int va):base(va,va){
a = va;
}
public override void Draw()
{
Console.WriteLine("RectEqualTriangle");
Console.WriteLine("*");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * * * *");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Mysharp
{
public class Rectangle:Sharp
{
protected int a;
protected int b;
public Rectangle ( int va,int vb){
a = va;
b = vb;
}
public override int GetArea(){
int area=a*b;
return area;
}
public override void Draw(){
Console.WriteLine("Rectangle");
Console.WriteLine("* * * *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * * *");
}
}
public class Square : Rectangle {
public Square(int va) : base(va,va) {;}
public override void Draw()
{
Console.WriteLine("Square");
Console.WriteLine("****");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("****");
}
}
public class RectEqualTriangle : Rectangle {
new protected int a;
public RectEqualTriangle(int va):base(va,va){
a = va;
}
public override void Draw()
{
Console.WriteLine("RectEqualTriangle");
Console.WriteLine("*");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("* * * * *");
}
}
}
//一个用来发送客户端消息的类代码
using System;
using System.Collections.Generic;
using System.Text;
namespace Mymessage
{
class Mymessage
{
}
public class Message
{
public void Begin()
{
Console.WriteLine("******* *********");
Console.WriteLine("* * * *");
Console.WriteLine("* * * *");
Console.WriteLine("******** * * ********");
Console.WriteLine("* * * * *");
Console.WriteLine("* * * *");
Console.WriteLine("* * * *");
Console.WriteLine("******* Sharp Gam *******");
Console.WriteLine("*************************");
}
public bool Ask() {
Console.WriteLine("Press 0 to Exit the Game");
Console.WriteLine("Press Any Key to Continue the Game");
Console.WriteLine();
int c = Console.Read();
if (c == 48) {
return false;}
else{
return true;
}
}
}
}
//客户端代码,也就是主程序
using System;
using System.Collections.Generic;
using System.Text;
using Mysharp;
using Mymessage;
namespace Mysharp
{
class ClientTest
{
public static void Main() {
int score = 1000;
int win;
int Choice;
int bet;
String s;
Sharp sp = new Sharp();
Random ran = new Random();
Message msg = new Message();
msg.Begin();
while (true) {
if (!msg.Ask()) {
Console.WriteLine("You Score:{0}",score);
Console.WriteLine("Enter Your Bet:");
s = Console.ReadLine();
try
{
bet = Convert.ToInt32(s);
}
catch {
bet = 100;
}
if (bet < score)
{
score -= bet;
}
else {
bet = score;
bet = 0;
}
Console.WriteLine("Remain Score:{0}",score);
win = 0;
for (int i = 0; i < 3; i++) {
Choice = ran.Next()%4;
switch(Choice){
case 0:
sp = new Rectangle(5, 4);
goto end;
case 1:
sp = new RectEqualTriangle(5);
goto end;
case 2:
sp = new Rectangle(5,4);
goto end;
case 3:
sp = new Square(5);
goto end;
}
end:
sp.Draw();
win += sp.GetArea() *(i + 1) * bet / 100;
Console.WriteLine("You win {0}",win);
}
score += win;
Console.WriteLine("You Score{0}",score);
if (score < 100) {
Console.WriteLine("You remain Score is not enough to Play!");
}
Console.ReadLine();
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Mysharp;
using Mymessage;
namespace Mysharp
{
class ClientTest
{
public static void Main() {
int score = 1000;
int win;
int Choice;
int bet;
String s;
Sharp sp = new Sharp();
Random ran = new Random();
Message msg = new Message();
msg.Begin();
while (true) {
if (!msg.Ask()) {
Console.WriteLine("You Score:{0}",score);
Console.WriteLine("Enter Your Bet:");
s = Console.ReadLine();
try
{
bet = Convert.ToInt32(s);
}
catch {
bet = 100;
}
if (bet < score)
{
score -= bet;
}
else {
bet = score;
bet = 0;
}
Console.WriteLine("Remain Score:{0}",score);
win = 0;
for (int i = 0; i < 3; i++) {
Choice = ran.Next()%4;
switch(Choice){
case 0:
sp = new Rectangle(5, 4);
goto end;
case 1:
sp = new RectEqualTriangle(5);
goto end;
case 2:
sp = new Rectangle(5,4);
goto end;
case 3:
sp = new Square(5);
goto end;
}
end:
sp.Draw();
win += sp.GetArea() *(i + 1) * bet / 100;
Console.WriteLine("You win {0}",win);
}
score += win;
Console.WriteLine("You Score{0}",score);
if (score < 100) {
Console.WriteLine("You remain Score is not enough to Play!");
}
Console.ReadLine();
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Mymessage
{
class Mymessage
{
}
public class Message
{
public void Begin()
{
Console.WriteLine("******* *********");
Console.WriteLine("* * * *");
Console.WriteLine("* * * *");
Console.WriteLine("******** * * ********");
Console.WriteLine("* * * * *");
Console.WriteLine("* * * *");
Console.WriteLine("* * * *");
Console.WriteLine("******* Sharp Gam *******");
Console.WriteLine("*************************");
}
public bool Ask() {
Console.WriteLine("Press 0 to Exit the Game");
Console.WriteLine("Press Any Key to Continue the Game");
Console.WriteLine();
int c = Console.Read();
if (c == 48) {
return false;}
else{
return true;
}
}
}
}
- 又是劳累的一天
- 劳累的一天
- 劳累的一天
- 劳累的一天
- 又是无聊的一天.
- 又是无聊的一天~
- 又是痛苦的一天
- 又是忙碌的一天
- 又是忙碌的一天
- 又是等待的一天
- 又是昏昏噩噩的一天
- 又是忙碌的一天
- 又是新的一天
- 又是痛苦的一天
- 又是新的一天
- 又是新的一天
- 又是忙碌的一天
- 又是新的一天
- 关于查找 “选修了全部课程的学生姓名”题目的理解--嘟嘟胖
- FF下高度自适应方法
- Linux下默认的宏测试
- SQL精华收集
- 运行第一个flex程序(3)
- 又是劳累的一天
- C++指向类成员的指针的使用(详细介绍)
- VC混合视图的分割
- 迅雷BT功能与IIS冲突导致0x8ffe2740错误
- 调试flex程序
- DotNet对同步的支持
- C语言部门考试,最后两道题总结
- 推荐一个代码生成工具Commonclipse
- openoffice下添加windows字体