HI everyone,
I have 2 classes:
-invader
-Game
for class: invader
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
namespace StarInvader2
{
[Serializable]
public class Invader
{
//InvaderType invaderType;
Form1 form1;
public Boolean hit = false;
Game game;
public Bitmap image;
public Point Location;
//public Point Location { get; private set; }
public Type InvaderType { get; private set; }
public Bitmap[][] InvaderImageBlock;
Bug bug = new Bug();
Saucer saucer = new Saucer();
Satalite satalite = new Satalite();
SpaceShip spaceShip = new SpaceShip();
Starss starss = new Starss();
//int x = GetScore(bug);
//int score = GetScore(bug);
/*
public int GetScore(Enemy enemy)
{
//int score = bug;
//int score1 = GetScore(saucer);
//int score2 = GetScore(satalite);
// int score3 = GetScore(spaceShip);
// int score4 = GetScore(starss);
//Console.WriteLine("{0} {1}", enemy.GetType(), enemy.KillerScore);
//return enemy.KillerScore;
}
*/
public Rectangle Area
{
get { return new Rectangle(Location, image.Size); }
}
public int Score { get; private set; }
public Invader(Type invaderType, Point location, int score)
{
//this.image = StarInvader2.Properties.Resources.bug1;
this.InvaderType = invaderType;
this.Location = location;
//this.Score = score;
this.image = InvaderImage(0);
//ScoreInvader(Score);
//gameScore(g);
}//End constructor.
public void Draw(Graphics g, int animationCell)
{
g.DrawImage(this.image, this.Location);
// Font drawfont = new Font("Arial", 25);
// g.DrawString(this.Score.ToString(), drawfont, Brushes.White, 1f, 1f);
}//End method
public static Bitmap ResizeImage(Image ImageToResize, int Width, int Height)
{
Bitmap bitmap = new Bitmap(ImageToResize);
using (Graphics graphics = Graphics.FromImage(bitmap))//Draw FromImage
{
graphics.DrawImage(ImageToResize, 0, 0, Width, Height);
}
return bitmap;
}//
private Bitmap InvaderImage(int animationCell)
// public void DisplayImage()
{
switch(InvaderType)
{
case Type.Bug:
switch(animationCell)
{
case 0:
return Properties.Resources.bug1;
case 1:
return Properties.Resources.bug2;
case 2:
return Properties.Resources.bug3;
case 3:
return Properties.Resources.bug4;
default:
break;
}//End swith(Bug)
break;
case Type.Saucer:
switch (animationCell)
{
case 0:
return Properties.Resources.flyingsaucer1;
case 1:
return Properties.Resources.flyingsaucer2;
case 2:
return Properties.Resources.flyingsaucer3;
case 3:
return Properties.Resources.flyingsaucer4;
default:
break;
}//End swith(Satelite)
break;
case Type.satelite:
switch (animationCell)
{
case 0:
return Properties.Resources.satellite1;
case 1:
return Properties.Resources.satellite2;
case 2:
return Properties.Resources.satellite3;
case 3:
return Properties.Resources.satellite4;
default:
break;
}//End swicth
break;
case Type.Spaceship:
switch (animationCell)
{
case 0:
return Properties.Resources.spaceship1;
case 1:
return Properties.Resources.spaceship2;
case 2:
return Properties.Resources.spaceship3;
case 3:
return Properties.Resources.spaceship4;
default:
break;
}//End switch
break;
case Type.star:
switch (animationCell)
{
case 0:
return Properties.Resources.star1;
case 1:
return Properties.Resources.star2;
case 2:
return Properties.Resources.star3;
case 3:
return Properties.Resources.star4;
default:
break;
}//End switch
break;
}//End swith(InvaderType)
return image;
}//End method
public void Move(Direction direction)
{
switch (direction)
{
case Direction.Down:
Location.Y += GameConstants.VerticalInterval;
break;
case Direction.Left:
Location.X -= GameConstants.HorizontalInterval;
break;
case Direction.Right:
Location.X += GameConstants.HorizontalInterval;
break;
case Direction.DownLeft:
Location.Y = GameConstants.VerticalInterval;
//Location.X -= GameConstants.HorizontalInterval;
break;
default: break;
}
} //End method
//}
//return image;
//}//End method
public int ScoreInvader(int Score)
{
Score = 0;
if (InvaderType == Type.Bug)
Score = GameConstants.BugScore;
else if (InvaderType == Type.satelite)
Score = GameConstants.SatelliteScore;
else if (InvaderType == Type.Saucer)
Score = GameConstants.SaucerScore;
else if (InvaderType == Type.Spaceship)
Score = GameConstants.SpaceshipScore;
else if (InvaderType == Type.star)
Score = GameConstants.StarScore;
/*
switch(InvaderType)
{
case Type.Bug:
//case Type.Bug:
Score += GameConstants.BugScore;
break;
case Type.satelite:
Score += GameConstants.SatelliteScore;
break;
case Type.Saucer:
Score += GameConstants.SaucerScore;
break;
case Type.Spaceship:
Score += GameConstants.SpaceshipScore;
break;
case Type.star:
Score += GameConstants.StarScore;
break;
default:
break;
}
*/
this.Score = Score;
return Score;
}//End method
public void UpdateInvaderImage(int animationCell)
{
image = InvaderImageBlock[(int)this.InvaderType][animationCell];
//imgae = InvaderImage[animationCell];
}
/*
public void Bitmap(int animationCell)
{
image = InvaderImage[animationCell];
}
*/
}
}
[/code]
and for class: game:
[code]
public void Draw(Graphics g, bool gameOver /*int animationCell*/ )
{
stars.Draw(g,boundaries);//Draws the stars on the form
if (!gameOver)
{
playerShip.Draw(g);//Draws the player on the form
foreach (Invader invader in invaders)
{
invader.Draw(g, animationCell);
gameScore(g, invader);
invader.ScoreInvader(score);
//invader.ScoreInvader(GameConstants.StarScore);
//MessageBox.Show("The score is:" + invader.ScoreInvader(GameConstants.StarScore));
}
foreach (Shot shot in playerShots)
shot.Draw(g);
foreach (Shot shot in invaderShots)
shot.Draw(g);
//foreach (Invader invader in invaders)
// {
// gameScore(g, invader);
// }
//invader.gameScore(g);
}
else
SetupStartScreen(g);
// form1.Invalidate();//To redraw part of the form that is "dirty".The Refresh() method is: Invalidate() + Update().
}//End method
public void gameScore(Graphics g, Invader invader)
{
Font drawfont = new Font("Arial", 25);
g.DrawString(invader.Score.ToString(), drawfont, Brushes.White, 60f, 35f);
invader.ScoreInvader(score);
//g.DrawString(graphicsBuffer, "SCORE: " + Convert.ToString(score), 10, 10, 16, FontStyle.Bold, Brushes.White);
// g.DrawString(invader.Score)
}
[code]
and Type:
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StarInvader2
{
public enum Type
{
Bug, //= 0,
Saucer, //= 1,
satelite, //= 2,
Spaceship,// = 3,
star //= 4
}
}
[/code]
But the score doesnt change.